package com.hdax.dmw.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dmw.dtos.item.HotItemsDto;
import com.hdax.dmw.dtos.item.ItemDescDto;
import com.hdax.dmw.entity.item.DmItem;
import com.hdax.dmw.item.mapstructs.HotItemsDtoMapper;
import com.hdax.dmw.item.mapstructs.ItemDescDtoMapper;
import com.hdax.dmw.item.service.DmItemService;
import com.hdax.dmw.utils.Result;
import com.hdax.dmw.item.mappers.DmItemMapper;
import com.hdax.dmw.utils.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author guoyisha
* @description 针对表【dm_item(节目表)】的数据库操作Service实现
* @createDate 2023-06-15 08:59:12
*/
@Service
public class DmItemServiceImpl extends ServiceImpl<DmItemMapper, DmItem>
    implements DmItemService{

    @Autowired
    private HotItemsDtoMapper itemsDtoMapper;

    @Override
    public List<HotItemsDto> hotItems(Long itemType1Id) {
        QueryWrapper<DmItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("itemType1Id",itemType1Id);
        queryWrapper.eq("isRecommend",1L);
        queryWrapper.orderByDesc("startTime");
        queryWrapper.last("limit 5");
        List<DmItem> list = list(queryWrapper);
        return itemsDtoMapper.toTargetList(list);
    }

    @Autowired
    private ItemDescDtoMapper descDtoMapper;


    //查询商品详情
    @Override
    public Result<ItemDescDto> getItems(Long itemId) {
        //查询商品详细属性信息
        DmItem dmItem = baseMapper.selectById(itemId);
        ItemDescDto dto = descDtoMapper.toTarget(dmItem);
        return ResultGenerator.genSuccessResult(dto);
    }
}




